package com.ruoyi.project.socket.encode;

import com.ruoyi.project.socket.packet.L1Packet;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * 编码器
 * @author Administrator
 *
 */
public class MsgPckEncode extends MessageToByteEncoder<L1Packet> {
    //编码器，将特定数据包编码成byte发送给终端
    @Override
    protected void encode(ChannelHandlerContext ctx, L1Packet l1Packet, ByteBuf buf) throws Exception {
        byte[] l1PacketBytes = l1Packet.l1Packet2Bytes();
        if(null!=l1PacketBytes&&l1PacketBytes.length>0)
            buf.writeBytes(l1PacketBytes);
    }
}
